package com.ship.dispatch.controller;

import com.ship.common.core.web.domain.JsonResult;
import com.ship.dispatch.bean.HomePage.ConHomePageShow;
import com.ship.dispatch.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 首页大屏 前端控制器
 *
 * @author zhangyh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/home/page")
@Api(value = "homePageStatistics", tags = "首页大屏前端控制器")
public class HomePageStatisticsController {

    @Autowired
    private HomePageService homePageService;

    /**
     * 更新统计图表缓存信息
     *
     * @return
     */
    @ApiOperation(value = "更新统计图表缓存信息")
    @GetMapping("/cache/update")
    public JsonResult cacheUpdate() {
        return JsonResult.success(homePageService.getStatistics(0));
    }

    /**
     * 获取统计图表信息
     *
     * @return
     */
    @ApiOperation(value = "获取统计图表信息")
    @GetMapping("/statistics")
    public JsonResult<Object> getStatistics() {
        Object resultObject = homePageService.getStatistics(1);
        return JsonResult.success(resultObject);
    }

    /**
     * 获取首页信息
     * @return
     * @throws ParseException
     */
    @GetMapping("/detailedInformation")
    public JsonResult<Object> getHomePage() throws ParseException {
        List<ConHomePageShow> resultObject = homePageService.getShipInfo();
        return JsonResult.success(resultObject);
    }
}
